package archimede;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Calendar;
import java.util.Scanner;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.UIManager;

import net.miginfocom.swing.MigLayout;

import com.itextpdf.text.Anchor;
import com.itextpdf.text.BadElementException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;

public class DatiEdificio extends JPanel {
  /**
   * valori tipo edificio
   */
  private String[] elTipoEdificio = { "", "Casa unifamiliare",
      "Casa bi-famigliare", "Casa Pluri-familiare", "Condominio",
      "Villa storica", "Baita", "Chiesa", "Scuola", "Appartamento", "altro" };
  /**
   * tipo edificio
   */
  private JComboBox tipoEdificio = new JComboBox(elTipoEdificio);
  /**
   * tipo edificio selezionato altro
   */
  private boolean modifyTipoEdificio = false;

  /**
   * { nomeIntestatario 0, cognomeIntestatario 1, nomeDIttaIntestatario 2, via
   * 3, civico 4, città 5, cap 6, provincia 7 }
   */
  private JTextField[] intestatario = new JTextField[8];
  // campo libero tipo edificio
  private JTextField tipoEdificioAltro = new JTextField() {
    @Override
    protected void paintComponent(Graphics g) {
      if (!isOpaque()) {
        int w = getWidth();
        int h = getHeight();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(UIManager.getColor("TextField.background"));
        g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.setColor(Color.BLACK);
        g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.dispose();
      }
      super.paintComponent(g);
    }
  };

  private JTextField giorno = new JTextField() {
    @Override
    protected void paintComponent(Graphics g) {
      if (!isOpaque()) {
        int w = getWidth();
        int h = getHeight();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(UIManager.getColor("TextField.background"));
        g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.setColor(Color.BLACK);
        g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.dispose();
      }
      super.paintComponent(g);
    }
  };
  private JTextField mese = new JTextField() {
    @Override
    protected void paintComponent(Graphics g) {
      if (!isOpaque()) {
        int w = getWidth();
        int h = getHeight();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(UIManager.getColor("TextField.background"));
        g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.setColor(Color.BLACK);
        g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.dispose();
      }
      super.paintComponent(g);
    }
  };
  private JTextField anno = new JTextField() {
    @Override
    protected void paintComponent(Graphics g) {
      if (!isOpaque()) {
        int w = getWidth();
        int h = getHeight();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(UIManager.getColor("TextField.background"));
        g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.setColor(Color.BLACK);
        g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.dispose();
      }
      super.paintComponent(g);
    }
  };
  private JTextField tecnico = new JTextField() {
    @Override
    protected void paintComponent(Graphics g) {
      if (!isOpaque()) {
        int w = getWidth();
        int h = getHeight();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(UIManager.getColor("TextField.background"));
        g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.setColor(Color.BLACK);
        g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.dispose();
      }
      super.paintComponent(g);
    }
  };

  private JTextField giornoSopraluogo = new JTextField() {
    @Override
    protected void paintComponent(Graphics g) {
      if (!isOpaque()) {
        int w = getWidth();
        int h = getHeight();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(UIManager.getColor("TextField.background"));
        g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.setColor(Color.BLACK);
        g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.dispose();
      }
      super.paintComponent(g);
    }
  };
  private JTextField meseSopraluogo = new JTextField() {
    @Override
    protected void paintComponent(Graphics g) {
      if (!isOpaque()) {
        int w = getWidth();
        int h = getHeight();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(UIManager.getColor("TextField.background"));
        g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.setColor(Color.BLACK);
        g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.dispose();
      }
      super.paintComponent(g);
    }
  };
  private JTextField annoSopraluogo = new JTextField() {
    @Override
    protected void paintComponent(Graphics g) {
      if (!isOpaque()) {
        int w = getWidth();
        int h = getHeight();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(UIManager.getColor("TextField.background"));
        g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.setColor(Color.BLACK);
        g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.dispose();
      }
      super.paintComponent(g);
    }
  };
  private JTextField tecnicoSopraluogo = new JTextField() {
    @Override
    protected void paintComponent(Graphics g) {
      if (!isOpaque()) {
        int w = getWidth();
        int h = getHeight();
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(UIManager.getColor("TextField.background"));
        g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.setColor(Color.BLACK);
        g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
        g2.dispose();
      }
      super.paintComponent(g);
    }
  };
  /**
   * { nome 0, cognome 1, ditta 2, via 3, civico 4, città 5, cap 6, provincia 7,
   * mail 8, cell 9, tel 10 }
   */
  private JTextField[] committente = new JTextField[11];

  private JRadioButton privato = new JRadioButton("privato");

  private JRadioButton ente = new JRadioButton("ente/ditta");

  private JRadioButton privatoCommittente = new JRadioButton("privato");

  private JRadioButton enteCommittente = new JRadioButton("ente/ditta");

  private StartingWindow st;

  private JLabel nomeEnteoDIttaCommittente = new JLabel(
      "          Nome dell'ente/ditta :");

  private JLabel nomeEnteoDItta = new JLabel("          Nome dell'ente/ditta :");

  private ProfessionistaPanel professionista;

  private JPanel row12 = new JPanel();

  protected void paintComponent(Graphics g) {
    setOpaque(false);
    g.drawImage(
        (new ImageIcon(ClassLoader.getSystemResource("sfondo.jpg"))).getImage(),
        0, 0, null);
    super.paintComponent(g);
  }

  public DatiEdificio(StartingWindow sta) {
    super();
    setOpaque(false);
    this.st = sta;
    professionista = new ProfessionistaPanel(st);
    setLayout(new MigLayout("", "", "25[]3[]3[]3[]3[]"));

    for (int i = 0; i < intestatario.length; i++) {
      intestatario[i] = new JTextField() {
        @Override
        protected void paintComponent(Graphics g) {
          if (!isOpaque()) {
            int w = getWidth();
            int h = getHeight();
            Graphics2D g2 = (Graphics2D) g.create();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(UIManager.getColor("TextField.background"));
            g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
            g2.setColor(Color.BLACK);
            g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
            g2.dispose();
          }
          super.paintComponent(g);
        }
      };
      if (i == 0 || i == 1 || i == 2 || i == 6)
        intestatario[i].addKeyListener(new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            if (c == '/' || c == '_' || c == '@' || c == '#' || c == '\\'
                || c == '|') {
              e.consume(); // ignore event
            }
          }
        });
    }
    for (int i = 0; i < committente.length; i++) {
      committente[i] = new JTextField() {
        @Override
        protected void paintComponent(Graphics g) {
          if (!isOpaque()) {
            int w = getWidth();
            int h = getHeight();
            Graphics2D g2 = (Graphics2D) g.create();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(UIManager.getColor("TextField.background"));
            g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
            g2.setColor(Color.BLACK);
            g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
            g2.dispose();
          }
          super.paintComponent(g);
        }
      };
      if (i == 0 || i == 1 || i == 2 || i == 6)
        committente[i].addKeyListener(new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            if (c == '/' || c == '_' || c == '@' || c == '#' || c == '\\'
                || c == '|') {
              e.consume(); // ignore event
            }
          }
        });
      else if (i == 9 || i == 10)
        committente[i].addKeyListener(new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            if (((c < '0') || (c > '9')) && (c != KeyEvent.VK_BACK_SPACE)) {
              e.consume(); // ignore event
            }
          }
        });
    }
    JLabel title = new JLabel("Dati edificio :");
    title.setFont(new Font("Arial", Font.BOLD, 20));

    JLabel tipoEdificioLabel = new JLabel("Tipologia edificio :");
    setCell(tipoEdificioLabel);
    tipoEdificio.setPreferredSize(new Dimension(350, 30));
    tipoEdificioAltro.setPreferredSize(new Dimension(350, 30));

    JLabel nomeIntestatarioLabel = new JLabel("Nome intestatario :");
    setCell(nomeIntestatarioLabel);
    intestatario[0].setPreferredSize(new Dimension(250, 30));

    JLabel cognomeIntestatarioLabel = new JLabel("Cognome :");
    setCell(cognomeIntestatarioLabel);
    intestatario[1].setPreferredSize(new Dimension(250, 30));

    setCell(nomeEnteoDItta);
    intestatario[2].setPreferredSize(new Dimension(350, 30));

    JLabel viaLabel = new JLabel("Via :");
    setCell(viaLabel);
    intestatario[3].setPreferredSize(new Dimension(417, 30));
    JLabel civicoLabel = new JLabel("Civico :");
    setCell(civicoLabel);
    intestatario[4].setPreferredSize(new Dimension(70, 30));

    JLabel cittaLabel = new JLabel("Citta' :");
    setCell(cittaLabel);
    intestatario[5].setPreferredSize(new Dimension(250, 30));

    JLabel capLabel = new JLabel("C.A.P. :");
    setCell(capLabel);
    intestatario[6].setPreferredSize(new Dimension(100, 30));

    JLabel dataAnalisiLabel = new JLabel("Data analisi diagnostica :");
    setCell(dataAnalisiLabel);

    JLabel tecnicoLabel = new JLabel("Tecnico esecutore delle misurazioni :");
    setCell(tecnicoLabel);

    JLabel dataSopraluogoLabel = new JLabel("Data  sopralluogo  :   ");
    setCell(dataSopraluogoLabel);

    JLabel esecutoreLabel = new JLabel("Tecnico esecutore del sopralluogo :");
    setCell(esecutoreLabel);

    Calendar cal = Calendar.getInstance();
    giorno.setText("" + cal.get(Calendar.DATE));
    mese.setText("" + (cal.get(Calendar.MONTH) + 1));
    anno.setText("" + cal.get(Calendar.YEAR));
    giornoSopraluogo.setText("" + cal.get(Calendar.DATE));
    meseSopraluogo.setText("" + (cal.get(Calendar.MONTH) + 1));
    annoSopraluogo.setText("" + cal.get(Calendar.YEAR));
    setCell();

    JLabel committenteLabel = new JLabel("Committente :");
    committenteLabel.setFont(new Font("Arial", Font.BOLD, 20));

    JLabel nomeCommittente = new JLabel("Nome committente:");
    setCell(nomeCommittente);
    committente[0].setPreferredSize(new Dimension(250, 30));

    JLabel cognomeCommittente = new JLabel("Cognome :");
    setCell(cognomeCommittente);
    committente[1].setPreferredSize(new Dimension(250, 30));

    setCell(nomeEnteoDIttaCommittente);
    committente[2].setPreferredSize(new Dimension(350, 30));

    JLabel viaC = new JLabel("Via :");
    setCell(viaC);
    committente[3].setPreferredSize(new Dimension(417, 30));

    JLabel civicoC = new JLabel("Civico :");
    setCell(civicoC);
    committente[4].setPreferredSize(new Dimension(70, 30));

    JLabel cittaC = new JLabel("Citta' :");
    setCell(cittaC);
    committente[5].setPreferredSize(new Dimension(250, 30));

    JLabel capC = new JLabel("C.A.P. :");
    setCell(capC);
    committente[6].setPreferredSize(new Dimension(100, 30));

    JLabel cellC = new JLabel("Cell. :");
    setCell(cellC);
    committente[9].setPreferredSize(new Dimension(350, 30));

    JLabel telef = new JLabel("Tel. :");
    setCell(telef);
    committente[10].setPreferredSize(new Dimension(350, 30));

    JLabel mailC = new JLabel("E-Mail :");
    setCell(mailC);
    committente[8].setPreferredSize(new Dimension(350, 30));

    JButton repeat = new JButton("Ripeti valori");
    repeat.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        committente[0].setText(intestatario[0].getText());
        committente[1].setText(intestatario[1].getText());
        committente[2].setText(intestatario[2].getText());
        privatoCommittente.setSelected(privato.isSelected());
        enteCommittente.setSelected(ente.isSelected());
        if (privatoCommittente.isSelected()) {
          nomeEnteoDIttaCommittente.setVisible(false);
          committente[2].setVisible(false);
        } else {
          nomeEnteoDIttaCommittente.setVisible(true);
          committente[2].setVisible(true);
        }

        committente[3].setText(intestatario[3].getText());
        committente[4].setText(intestatario[4].getText());
        committente[5].setText(intestatario[5].getText());
        committente[6].setText(intestatario[6].getText());
        committente[7].setText(intestatario[7].getText());
        paintAll(getGraphics());
      }
    });

    ente.setSelected(true);
    privato.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        ente.setSelected(false);

        privato.setSelected(true);
        nomeEnteoDItta.setVisible(false);
        intestatario[2].setVisible(false);
      }

    });

    ente.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        privato.setSelected(false);

        ente.setSelected(true);
        nomeEnteoDItta.setVisible(true);
        intestatario[2].setVisible(true);
      }
    });

    enteCommittente.setSelected(true);
    privatoCommittente.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        enteCommittente.setSelected(false);

        privatoCommittente.setSelected(true);
        nomeEnteoDIttaCommittente.setVisible(false);
        committente[2].setVisible(false);
      }

    });

    enteCommittente.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        privatoCommittente.setSelected(false);

        enteCommittente.setSelected(true);
        nomeEnteoDIttaCommittente.setVisible(true);
        committente[2].setVisible(true);
      }
    });
    // divido in pannelli

    row12.setLayout(new MigLayout());
    row12.setOpaque(false);

    row12.add(tipoEdificioLabel, "cell 0 0 2 1");
    row12.add(tipoEdificio, "cell 2 0 3 1");
    row12.add(nomeIntestatarioLabel, "cell 0 1 2 1");
    row12.add(intestatario[0], "cell 2 1");
    row12.add(cognomeIntestatarioLabel, "cell 3 1");
    row12.add(intestatario[1], "cell 4 1");
    row12.add(privato, "cell 0 2");
    row12.add(ente, "cell 1 2");
    row12.add(nomeEnteoDItta, "cell 2 2 ");
    row12.add(intestatario[2], "cell 3 2 3 1");

    tipoEdificio.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        if (((String) tipoEdificio.getSelectedItem()).equalsIgnoreCase("altro")) {
          row12.remove(tipoEdificio);
          row12.add(tipoEdificioAltro, "cell 2 0 3 1");
          modifyTipoEdificio = true;
          paintAll(getGraphics());
        } else if (((String) tipoEdificio.getSelectedItem())
            .equalsIgnoreCase("Appartamento")) {
          row12.remove(tipoEdificio);
          tipoEdificioAltro.setText("Appartamento al piano ");
          row12.add(tipoEdificioAltro, "cell 2 0 3 1");
          modifyTipoEdificio = true;
          paintAll(getGraphics());
        }
      }
    });
    MouseAdapter ml = new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON3) {
          row12.remove(tipoEdificioAltro);
          tipoEdificio.setSelectedIndex(0);
          row12.add(tipoEdificio, "cell 2 0 3 1");
          modifyTipoEdificio = false;
          paintAll(getGraphics());
        }
      }
    };
    tipoEdificioAltro.addMouseListener(ml);

    JPanel row345 = new JPanel();
    row345.setLayout(new MigLayout());
    row345.setOpaque(false);
    row345.add(viaLabel, "cell 0 0");
    row345.add(intestatario[3], "cell 1 0 3 1");
    row345.add(civicoLabel, "cell 4 0");
    row345.add(intestatario[4], "cell 5 0");
    row345.add(cittaLabel, "cell 0 1");
    row345.add(intestatario[5], "cell 1 1");
    row345.add(capLabel, "cell 2 1");
    row345.add(intestatario[6], "cell 3 1");
    row345.add(new JLabel("Provincia") {
      @Override
      public void setFont(Font font) {
        // TODO Auto-generated method stub
        super.setFont(new Font("Arial", Font.BOLD, 16));
      }
    }, "cell 4 1");
    row345.add(intestatario[7], "cell 5 1");

    JPanel row67 = new JPanel();
    row67.setLayout(new MigLayout());
    row67.setOpaque(false);
    row67.add(dataAnalisiLabel);
    row67.add(giorno);

    row67.add(mese);

    row67.add(anno, "wrap");

    row67.add(tecnicoLabel, "span 3");
    row67.add(tecnico);

    JPanel esecutore = new JPanel();
    esecutore.setLayout(new MigLayout());
    esecutore.setOpaque(false);
    esecutore.add(dataSopraluogoLabel);
    esecutore.add(giornoSopraluogo);
    esecutore.add(meseSopraluogo);
    esecutore.add(annoSopraluogo, "wrap");
    esecutore.add(esecutoreLabel, "span 3");
    esecutore.add(tecnicoSopraluogo);

    add(title, "wrap , gapleft 20");
    add(row12, "wrap, gapleft 15");
    add(row345, "wrap, gapleft 15");
    add(row67, "wrap, gapleft 15");
    add(esecutore, "wrap, gapleft 15");

    JPanel cmtt = new JPanel();
    cmtt.setLayout(new MigLayout());
    cmtt.setOpaque(false);
    cmtt.add(committenteLabel);
    cmtt.add(repeat);

    JPanel Crow12 = new JPanel();
    Crow12.setLayout(new MigLayout());
    Crow12.setOpaque(false);
    Crow12.add(nomeCommittente, "cell 0 1 2 1");
    Crow12.add(committente[0], "cell 2 1");
    Crow12.add(cognomeCommittente, "cell 3 1");
    Crow12.add(committente[1], "cell 4 1");
    Crow12.add(privatoCommittente, "cell 0 2");
    Crow12.add(enteCommittente, "cell 1 2");
    Crow12.add(nomeEnteoDIttaCommittente, "cell 2 2 ");
    Crow12.add(committente[2], "cell 3 2 3 1");

    JPanel Crow345 = new JPanel();
    Crow345.setLayout(new MigLayout());
    Crow345.setOpaque(false);
    Crow345.add(viaC, "cell 0 0");
    Crow345.add(committente[3], "cell 1 0 3 1");
    Crow345.add(civicoC, "cell 4 0");
    Crow345.add(committente[4], "cell 5 0");
    Crow345.add(cittaC, "cell 0 1");
    Crow345.add(committente[5], "cell 1 1");
    Crow345.add(capC, "cell 2 1");
    Crow345.add(committente[6], "cell 3 1");
    Crow345.add(new JLabel("Provincia") {
      @Override
      public void setFont(Font font) {
        // TODO Auto-generated method stub
        super.setFont(new Font("Arial", Font.BOLD, 16));
      }
    }, "cell 4 1");
    Crow345.add(committente[7], "cell 5 1");

    JPanel Crow67 = new JPanel();
    Crow67.setLayout(new MigLayout());
    Crow67.setOpaque(false);
    Crow67.add(mailC, "cell 0 0");
    Crow67.add(committente[8], "cell 1 0");
    Crow67.add(cellC, "cell 0 1");
    Crow67.add(committente[9], "cell 1 1");
    Crow67.add(telef, "cell 0 2");
    Crow67.add(committente[10]);

    add(cmtt, "wrap , gapleft 15");
    add(Crow12, "wrap, gapleft 15");
    add(Crow345, "wrap, gapleft 15");
    add(Crow67, "wrap, gapleft 15");

    add(professionista, "gapleft 15");

  }

  public void setCell(JComponent c) {
    c.setFont(new Font("Arial", Font.BOLD, 16));
  }

  public void setCell() {
    tipoEdificioAltro.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    intestatario[0].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    intestatario[1].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    intestatario[2].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    intestatario[3].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    intestatario[4].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    intestatario[5].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    intestatario[6].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    intestatario[7].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));

    giorno.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    mese.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    anno.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    tecnico.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    giornoSopraluogo.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    meseSopraluogo.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    annoSopraluogo.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    tecnicoSopraluogo.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));

    committente[0].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[1].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[2].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[3].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[4].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[5].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[6].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[7].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[8].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[9].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
    committente[10].setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));

    tipoEdificio.setFont(new Font("Arial", Font.PLAIN, 16));
    tipoEdificioAltro.setFont(new Font("Arial", Font.PLAIN, 16));
    intestatario[0].setFont(new Font("Arial", Font.PLAIN, 16));
    intestatario[1].setFont(new Font("Arial", Font.PLAIN, 16));
    intestatario[2].setFont(new Font("Arial", Font.PLAIN, 16));
    intestatario[3].setFont(new Font("Arial", Font.PLAIN, 16));
    intestatario[4].setFont(new Font("Arial", Font.PLAIN, 16));
    intestatario[5].setFont(new Font("Arial", Font.PLAIN, 16));
    intestatario[6].setFont(new Font("Arial", Font.PLAIN, 16));
    intestatario[7].setFont(new Font("Arial", Font.PLAIN, 16));
    giorno.setFont(new Font("Arial", Font.PLAIN, 16));
    mese.setFont(new Font("Arial", Font.PLAIN, 16));
    anno.setFont(new Font("Arial", Font.PLAIN, 16));
    tecnico.setFont(new Font("Arial", Font.PLAIN, 16));
    giornoSopraluogo.setFont(new Font("Arial", Font.PLAIN, 16));
    meseSopraluogo.setFont(new Font("Arial", Font.PLAIN, 16));
    annoSopraluogo.setFont(new Font("Arial", Font.PLAIN, 16));
    tecnicoSopraluogo.setFont(new Font("Arial", Font.PLAIN, 16));

    committente[0].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[1].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[2].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[3].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[4].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[5].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[6].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[7].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[8].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[9].setFont(new Font("Arial", Font.PLAIN, 16));
    committente[10].setFont(new Font("Arial", Font.PLAIN, 16));

    giorno.setPreferredSize(new Dimension(50, 30));
    mese.setPreferredSize(new Dimension(50, 30));
    anno.setPreferredSize(new Dimension(70, 30));
    tecnico.setPreferredSize(new Dimension(300, 30));
    giornoSopraluogo.setPreferredSize(new Dimension(50, 30));
    meseSopraluogo.setPreferredSize(new Dimension(50, 30));
    annoSopraluogo.setPreferredSize(new Dimension(70, 30));
    tecnicoSopraluogo.setPreferredSize(new Dimension(300, 30));
    intestatario[7].setPreferredSize(new Dimension(70, 30));
    committente[7].setPreferredSize(new Dimension(70, 30));

    tipoEdificio.setOpaque(false);
    tipoEdificioAltro.setOpaque(false);

    intestatario[0].setOpaque(false);
    intestatario[1].setOpaque(false);
    intestatario[2].setOpaque(false);
    intestatario[3].setOpaque(false);
    intestatario[4].setOpaque(false);
    intestatario[5].setOpaque(false);
    intestatario[6].setOpaque(false);
    intestatario[7].setOpaque(false);

    giorno.setOpaque(false);
    mese.setOpaque(false);
    anno.setOpaque(false);
    tecnico.setOpaque(false);
    giornoSopraluogo.setOpaque(false);
    meseSopraluogo.setOpaque(false);
    annoSopraluogo.setOpaque(false);
    tecnicoSopraluogo.setOpaque(false);

    committente[0].setOpaque(false);
    committente[1].setOpaque(false);
    committente[2].setOpaque(false);
    committente[3].setOpaque(false);
    committente[4].setOpaque(false);
    committente[5].setOpaque(false);
    committente[6].setOpaque(false);
    committente[7].setOpaque(false);
    committente[8].setOpaque(false);
    committente[9].setOpaque(false);
    committente[10].setOpaque(false);
  }

  public String print() {
    String print = "";

    if (modifyTipoEdificio)
      print = print + "#" + tipoEdificioAltro.getText();
    else
      print = print + "#" + tipoEdificio.getSelectedIndex();
    // mod
    print = print + "\n#" + intestatario[0].getText();
    print = print + "\n#" + intestatario[1].getText();
    print = print + "\n#" + privato.isSelected();
    print = print + "\n#" + intestatario[2].getText();
    print = print + "\n#" + intestatario[3].getText();
    print = print + "\n#" + intestatario[4].getText();
    print = print + "\n#" + intestatario[5].getText();
    print = print + "\n#" + intestatario[6].getText();
    print = print + "\n#" + intestatario[7].getText();

    print = print + "\n#" + giorno.getText();
    print = print + "\n#" + mese.getText();
    print = print + "\n#" + anno.getText();
    print = print + "\n#" + tecnico.getText();
    print = print + "\n#" + giornoSopraluogo.getText();
    print = print + "\n#" + meseSopraluogo.getText();
    print = print + "\n#" + annoSopraluogo.getText();
    print = print + "\n#" + tecnicoSopraluogo.getText();

    print = print + "\n#" + committente[0].getText();
    print = print + "\n#" + committente[1].getText();
    print = print + "\n#" + privatoCommittente.isSelected();
    print = print + "\n#" + committente[2].getText();
    print = print + "\n#" + committente[3].getText();
    print = print + "\n#" + committente[4].getText();
    print = print + "\n#" + committente[5].getText();
    print = print + "\n#" + committente[6].getText();
    print = print + "\n#" + committente[7].getText();
    print = print + "\n#" + committente[8].getText();
    print = print + "\n#" + committente[9].getText();
    print = print + "\n#" + committente[10].getText();

    print = print + professionista.print();

    return print;

  }

  public void setElement(String data) {
    Scanner c = new Scanner(data);
    c.nextLine();

    String tmp = c.nextLine();
    try {
      tipoEdificio.setSelectedIndex(Integer.parseInt(tmp));
    } catch (NumberFormatException e) {
      tipoEdificioAltro.setText(tmp);
      row12.remove(tipoEdificio);
      row12.add(tipoEdificioAltro, "cell 2 0 3 1");
      modifyTipoEdificio = true;

    }
    intestatario[0].setText(c.nextLine());
    intestatario[1].setText(c.nextLine());
    if (c.nextLine().equals("true")) {
      privato.setSelected(true);
      ente.setSelected(false);
      nomeEnteoDItta.setVisible(false);
      intestatario[2].setVisible(false);
    } else {
      ente.setSelected(true);
      privato.setSelected(false);
      nomeEnteoDItta.setVisible(true);
      intestatario[2].setVisible(true);
    }
    try {
      intestatario[2].setText(c.nextLine());
    } catch (Exception e) {
      intestatario[2].setText("");
    }

    intestatario[3].setText(c.nextLine());
    intestatario[4].setText(c.nextLine());
    intestatario[5].setText(c.nextLine());
    intestatario[6].setText(c.nextLine());
    intestatario[7].setText(c.nextLine());
    giorno.setText(c.nextLine());
    mese.setText(c.nextLine());
    anno.setText(c.nextLine());
    tecnico.setText(c.nextLine());

    giornoSopraluogo.setText(c.nextLine());
    meseSopraluogo.setText(c.nextLine());
    annoSopraluogo.setText(c.nextLine());
    tecnicoSopraluogo.setText(c.nextLine());

    committente[0].setText(c.nextLine());
    committente[1].setText(c.nextLine());
    if (c.nextLine().equals("true")) {
      privatoCommittente.setSelected(true);
      enteCommittente.setSelected(false);
      nomeEnteoDIttaCommittente.setVisible(false);
      committente[2].setVisible(false);
    } else {
      enteCommittente.setSelected(true);
      privatoCommittente.setSelected(false);
      nomeEnteoDIttaCommittente.setVisible(true);
      committente[2].setVisible(true);
    }
    try {
      committente[2].setText(c.nextLine());
    } catch (Exception e) {
      committente[2].setText("");
    }

    committente[3].setText(c.nextLine());
    committente[4].setText(c.nextLine());
    committente[5].setText(c.nextLine());
    committente[6].setText(c.nextLine());
    committente[7].setText(c.nextLine());
    committente[8].setText(c.nextLine());
    committente[9].setText(c.nextLine());
    try {
      committente[10].setText(c.nextLine());
    } catch (Exception e) {
      committente[10].setText("");
    }

  }

  public void setProfessionista(String data) {
    professionista.setElement(data);
  }

  public String getProject() {
    if (privatoCommittente.isSelected())
      return st.getCount() + "_" + committente[1].getText() + "_"
          + committente[0].getText() + "_" + committente[7].getText();
    return st.getCount() + "_" + committente[2].getText() + "_"
        + committente[7].getText();
  }

  public Document PDFfront(Document doc) {
    Paragraph dati = new Paragraph("ARCHIMEDE GROUP", FontFactory.getFont(
        FontFactory.TIMES, 16.0F));
    try {
      dati.setSpacingAfter(10.0F);
      dati.setAlignment(1);
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    try {
      Image logo = Image.getInstance(ClassLoader.getSystemResource("logo.jpg"));
      logo.setAbsolutePosition(doc.getPageSize().getWidth() / 2.0F - 80.0F,
          540.0F);
      logo.scaleAbsolute(160.0F, 160.0F);
      doc.add(logo);
    } catch (BadElementException e1) {
      e1.printStackTrace();
    } catch (MalformedURLException e1) {
      e1.printStackTrace();
    } catch (IOException e1) {
      e1.printStackTrace();
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    dati = new Paragraph("RTD " + (this.st.getCount() + 346),
        FontFactory.getFont(FontFactory.TIMES, 26.0F));
    try {
      dati.setSpacingAfter(10.0F);
      dati.setSpacingBefore(250.0F);
      dati.setAlignment(1);
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    dati = new Paragraph("_____________________________________",
        FontFactory.getFont(FontFactory.TIMES, 26.0F, new BaseColor(0, 102, 255)));
    try {
      dati.setSpacingAfter(20.0F);
      dati.setAlignment(1);
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    dati = new Paragraph("RELAZIONE TECNICA DIAGNOSTICA", FontFactory.getFont(
        FontFactory.TIMES, 20.0F));
    dati.setAlignment(1);
    dati.setSpacingAfter(30.0F);
    dati.setSpacingBefore(30.0F);
    try {
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    if (this.modifyTipoEdificio)
      dati = new Paragraph(this.tipoEdificioAltro.getText(),
          FontFactory.getFont(FontFactory.TIMES, 18.0F));
    else
      dati = new Paragraph((String) this.tipoEdificio.getSelectedItem(),
          FontFactory.getFont(FontFactory.TIMES, 18.0F));
    dati.setAlignment(1);
    try {
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    if (this.ente.isSelected()) {
      dati = new Paragraph(this.intestatario[2].getText(), FontFactory.getFont(
          FontFactory.TIMES, 18.0F));
      dati.setAlignment(1);
      try {
        doc.add(dati);
      } catch (DocumentException e) {
        e.printStackTrace();
      }
    }
    if (!this.intestatario[1].getText().equals("")) {
      dati = new Paragraph(this.intestatario[1].getText() + "  "
          + this.intestatario[0].getText(), FontFactory.getFont(FontFactory.TIMES, 18.0F));
      dati.setAlignment(1);
      try {
        doc.add(dati);
      } catch (DocumentException e) {
        e.printStackTrace();
      }
    }

    if (intestatario[4].getText().equals(""))
      dati = new Paragraph("Via " + this.intestatario[3].getText(),
          FontFactory.getFont(FontFactory.TIMES, 18.0F));
    else
      dati = new Paragraph("Via " + this.intestatario[3].getText() + " , "
          + this.intestatario[4].getText(), FontFactory.getFont(FontFactory.TIMES, 18.0F));
    dati.setAlignment(1);
    try {
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    if (intestatario[6].getText().equals(""))
      dati = new Paragraph(this.intestatario[5].getText() + " ("
          + this.intestatario[7].getText() + ")", FontFactory.getFont(FontFactory.TIMES,
          18.0F));
    else
      dati = new Paragraph(this.intestatario[6].getText() + " "
          + this.intestatario[5].getText() + " ("
          + this.intestatario[7].getText() + ")", FontFactory.getFont(FontFactory.TIMES,
          18.0F));
    dati.setAlignment(1);
    try {
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }
    
    return doc;
  }

  public Document PDFindice(Document doc) {
    PdfPTable table = new PdfPTable(2);
    int[] size = { 320, 460 };
    try {
      table.setWidths(size);
      table.setWidthPercentage(100.0F);
    } catch (DocumentException e1) {
      e1.printStackTrace();
    }

    String line = "";

    if (this.modifyTipoEdificio) {
      line = this.tipoEdificioAltro.getText();
    } else {
      line = (String) this.tipoEdificio.getSelectedItem();
    }
    Phrase testo = new Phrase("Immobile    ...........................",
        FontFactory.getFont(FontFactory.TIMES, 12.0F));
    PdfPCell cos = new PdfPCell(testo);
    cos.setHorizontalAlignment(0);
    cos.setVerticalAlignment(4);
    cos.setRowspan(3);
    cos.setBorder(0);
    table.addCell(cos);

    testo = new Phrase(line, FontFactory.getFont(FontFactory.TIMES, 12.0F));
    cos = new PdfPCell(testo);
    cos.setHorizontalAlignment(0);
    cos.setVerticalAlignment(4);
    cos.setBorder(0);
    table.addCell(cos);

    if (intestatario[4].getText().equals(""))
      testo = new Phrase("Via " + this.intestatario[3].getText(),
          FontFactory.getFont(FontFactory.TIMES, 12.0F));
    else
      testo = new Phrase("Via " + this.intestatario[3].getText() + " , "
          + this.intestatario[4].getText(), FontFactory.getFont(FontFactory.TIMES, 12.0F));
    cos = new PdfPCell(testo);
    cos.setHorizontalAlignment(0);
    cos.setVerticalAlignment(4);
    cos.setBorder(0);
    table.addCell(cos);

    if (intestatario[6].getText().equals(""))
      testo = new Phrase(this.intestatario[5].getText() + " ("
          + this.intestatario[7].getText() + ")", FontFactory.getFont(FontFactory.TIMES,
          12.0F));
    else
      testo = new Phrase(this.intestatario[6].getText() + " "
          + this.intestatario[5].getText() + " ("
          + this.intestatario[7].getText() + ")", FontFactory.getFont(FontFactory.TIMES,
          12.0F));
    cos = new PdfPCell(testo);
    cos.setHorizontalAlignment(0);
    cos.setVerticalAlignment(4);
    cos.setBorder(0);
    table.addCell(cos);
    try {
      doc.add(table);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    table = new PdfPTable(2);
    try {
      table.setWidths(size);
      table.setWidthPercentage(100.0F);
    } catch (DocumentException e1) {
      e1.printStackTrace();
    }

    testo = new Phrase("Committente    .....................",
        FontFactory.getFont(FontFactory.TIMES, 12.0F));
    cos = new PdfPCell(testo);
    cos.setHorizontalAlignment(0);
    cos.setVerticalAlignment(4);
    cos.setRowspan(7);
    cos.setBorder(0);
    table.addCell(cos);

    boolean span = false;

    if (this.enteCommittente.isSelected()) {
      testo = new Phrase(this.committente[2].getText(), FontFactory.getFont(
          FontFactory.TIMES, 12.0F));
      cos = new PdfPCell(testo);
      cos.setHorizontalAlignment(0);
      cos.setVerticalAlignment(4);
      cos.setBorder(0);
      table.addCell(cos);
      if (!this.committente[1].getText().equals("")) {
        testo = new Phrase(this.committente[1].getText() + " "
            + this.committente[0].getText(),
            FontFactory.getFont(FontFactory.TIMES, 12.0F));
        cos = new PdfPCell(testo);
        cos.setHorizontalAlignment(0);
        cos.setVerticalAlignment(4);
        cos.setBorder(0);
        table.addCell(cos);
      } else {
        span = true;
      }
    } else {
      testo = new Phrase(this.committente[0].getText() + " "
          + this.committente[1].getText(), FontFactory.getFont(FontFactory.TIMES, 12.0F));
      cos = new PdfPCell(testo);
      cos.setHorizontalAlignment(0);
      cos.setVerticalAlignment(4);
      cos.setBorder(0);
      table.addCell(cos);
    }

    if (committente[4].getText().equals(""))
      testo = new Phrase("Via " + this.committente[3].getText(),
          FontFactory.getFont(FontFactory.TIMES, 12.0F));
    else
      testo = new Phrase("Via " + this.committente[3].getText() + " , "
          + this.committente[4].getText(), FontFactory.getFont(FontFactory.TIMES, 12.0F));
    cos = new PdfPCell(testo);
    cos.setHorizontalAlignment(0);
    cos.setVerticalAlignment(4);
    cos.setBorder(0);
    table.addCell(cos);

    if (committente[6].getText().equals(""))
      testo = new Phrase(this.committente[5].getText() + " ("
          + this.committente[7].getText() + ")", FontFactory.getFont(FontFactory.TIMES,
          12.0F));
    else
      testo = new Phrase(this.committente[6].getText() + " "
          + this.committente[5].getText() + " ("
          + this.committente[7].getText() + ")", FontFactory.getFont(FontFactory.TIMES,
          12.0F));
    cos = new PdfPCell(testo);
    cos.setHorizontalAlignment(0);
    cos.setVerticalAlignment(4);
    cos.setBorder(0);
    table.addCell(cos);

    if (!committente[8].getText().equals("")) {
      testo = new Phrase("Email: " + this.committente[8].getText(),
          FontFactory.getFont(FontFactory.TIMES, 12.0F));
      cos = new PdfPCell(testo);
      cos.setHorizontalAlignment(0);
      cos.setVerticalAlignment(4);
      cos.setBorder(0);
      table.addCell(cos);
    }

    if (!committente[9].getText().equals("")) {
      testo = new Phrase("Cell. " + this.committente[9].getText(),
          FontFactory.getFont(FontFactory.TIMES, 12.0F));
      cos = new PdfPCell(testo);
      cos.setHorizontalAlignment(0);
      cos.setVerticalAlignment(4);
      cos.setBorder(0);
      table.addCell(cos);
    }

    if (!committente[10].getText().equals("")) {
      testo = new Phrase("Tel. " + this.committente[10].getText(),
          FontFactory.getFont(FontFactory.TIMES, 12.0F));
      cos = new PdfPCell(testo);
      cos.setHorizontalAlignment(0);
      cos.setVerticalAlignment(4);
      cos.setBorder(0);
      table.addCell(cos);
    }

    Paragraph dati = new Paragraph("", FontFactory.getFont(FontFactory.TIMES, 13.0F, 1));
    try {
      dati.setSpacingBefore(20.0F);
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }
    try {
      doc.add(table);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    int numeroProfessionisti = this.professionista.pdf(doc);

    dati = new Paragraph("SOMMARIO", FontFactory.getFont(FontFactory.TIMES, 13.0F, 1));
    dati.setAlignment(0);
    try {
      if (numeroProfessionisti == 0)
        dati.setSpacingBefore(80.0F);
      else if (numeroProfessionisti == 1)
        dati.setSpacingBefore(60.0F);
      if (numeroProfessionisti == 2)
        dati.setSpacingBefore(20.0F);
      dati.setSpacingAfter(10.0F);
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    Anchor anchor = new Anchor("1.       Premesse", FontFactory.getFont(
        FontFactory.TIMES, 12.0F));
    anchor.setReference("#premesse");
    Paragraph paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    anchor = new Anchor("2.       Dati climatici ambientali",
        FontFactory.getFont(FontFactory.TIMES, 12.0F));
    anchor.setReference("#ambiente");
    paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    anchor = new Anchor("3.       Dati dell'immobile", FontFactory.getFont(
        FontFactory.TIMES, 12.0F));
    anchor.setReference("#immobile");
    paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    dati = new Paragraph("   3.1  Caratteristiche dei muri e delle pareti ",
        FontFactory.getFont(FontFactory.TIMES, 12.0F));
    dati.setAlignment(0);
    try {
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }
    dati = new Paragraph("   3.2  Impermeabilizzazioni ", FontFactory.getFont(
        FontFactory.TIMES, 12.0F));
    dati.setAlignment(0);
    try {
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }
    dati = new Paragraph(
        "   3.3  Tipo dell'intonaco, della pittura e periodo ",
        FontFactory.getFont(FontFactory.TIMES, 12.0F));
    dati.setAlignment(0);
    try {
      doc.add(dati);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    anchor = new Anchor("4.       Strumentazione utilizzata e condizioni",
        FontFactory.getFont(FontFactory.TIMES, 12.0F));
    anchor.setReference("#strumentazione");
    paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    anchor = new Anchor("5.       Pianta dell'edificio con punti di rilievo",
        FontFactory.getFont(FontFactory.TIMES, 12.0F));
    anchor.setReference("#pianta");
    paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    anchor = new Anchor(
        "6.       Report termografico e rilievo umidita' con metodo ponderale Darr",
        FontFactory.getFont(FontFactory.TIMES, 12.0F));
    anchor.setReference("#m");
    paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    anchor = new Anchor("7.       Analisi tipologia sali", FontFactory.getFont(
        FontFactory.TIMES, 12.0F));
    anchor.setReference("#sali");
    paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    anchor = new Anchor("8.       Potenziali elettrici", FontFactory.getFont(
        FontFactory.TIMES, 12.0F));
    anchor.setReference("#potenziali");
    paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    anchor = new Anchor("9.       Punti critici e soluzioni",
        FontFactory.getFont(FontFactory.TIMES, 12.0F));
    anchor.setReference("#critici");
    paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    anchor = new Anchor("10.       Conclusioni", FontFactory.getFont(FontFactory.TIMES,
        12.0F));
    anchor.setReference("#conclusioni");
    paragraph = new Paragraph();
    paragraph.add(anchor);

    try {
      doc.add(paragraph);
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    return doc;
  }

  public Document PDFpremesse(Document doc) {
    // clima
    Chunk underline = new Chunk("1.Premesse", FontFactory.getFont(
        FontFactory.TIMES, 15, Font.BOLD));
    underline.setUnderline(1.2f, -2f); // 0.1 thick, -2 y-location

    Anchor anchorTarget = new Anchor(underline);
    anchorTarget.setName("premesse");
    Paragraph targetParagraph = new Paragraph();
    targetParagraph.add(anchorTarget);
    try {
      doc.add(targetParagraph);
    } catch (DocumentException e2) {
      e2.printStackTrace();
    }
    Paragraph dati = new Paragraph("Data analisi diagnostica : "
        + this.giorno.getText() + "/" + this.mese.getText() + "/"
        + this.anno.getText(), FontFactory.getFont(FontFactory.TIMES, 12.0F));
    try {
      doc.add(dati);
    } catch (DocumentException e2) {
      e2.printStackTrace();
    }

    dati = new Paragraph("Tecnico esecutore delle misurazioni : "
        + this.tecnico.getText(), FontFactory.getFont(FontFactory.TIMES, 12.0F));
    try {
      if (giornoSopraluogo.getText().equals(""))
        dati.setSpacingAfter(10.0F);
      doc.add(dati);
    } catch (DocumentException e2) {
      e2.printStackTrace();
    }

    if (!giornoSopraluogo.getText().equals("")) {
      dati = new Paragraph(
          "Data sopralluogo : " + this.giornoSopraluogo.getText() + "/"
              + this.meseSopraluogo.getText() + "/"
              + this.annoSopraluogo.getText(), FontFactory.getFont(FontFactory.TIMES,
              12.0F));
      try {
        doc.add(dati);
      } catch (DocumentException e2) {
        e2.printStackTrace();
      }
    }

    if (!tecnicoSopraluogo.getText().equals("")) {
      dati = new Paragraph("Tecnico esecutore del sopralluogo : "
          + this.tecnicoSopraluogo.getText(), FontFactory.getFont(FontFactory.TIMES,
          12.0F));
      try {
        dati.setSpacingAfter(10.0F);
        doc.add(dati);
      } catch (DocumentException e2) {
        e2.printStackTrace();
      }
    } else {
      dati = new Paragraph("", FontFactory.getFont(FontFactory.TIMES, 12.0F));
      try {
        dati.setSpacingAfter(10.0F);
        doc.add(dati);
      } catch (DocumentException e2) {
        e2.printStackTrace();
      }

    }

    return doc;
  }
}
